﻿using System.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;

namespace Padsurface.App.UserControls
{
    public sealed partial class BeatCounterUserControl : UserControl
    {
        public string Beat
        {
            get { return (string)GetValue(BeatProperty); }
            set { SetValue(BeatProperty, value); }
        }

        public static readonly DependencyProperty BeatProperty =
            DependencyProperty.Register("Beat", typeof(string), typeof(BeatCounterUserControl), new PropertyMetadata(string.Empty, new PropertyChangedCallback(BpmChanged)));

        private static void BpmChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var beatCounterUserControl = (d as BeatCounterUserControl);
            beatCounterUserControl.beatStoryboard.Stop();

            Storyboard.SetTarget(beatCounterUserControl.beatStoryboard, beatCounterUserControl.beatSolidColorBrush);

            beatCounterUserControl.beatStoryboard.Begin();
        }

        public BeatCounterUserControl()
        {
            this.InitializeComponent();
        }
    }
}